package com.healthtop.web;

import com.healthtop.model.XsComment;
import com.healthtop.service.XsCommentService;
import com.healthtop.utils.AjaxResponseStatus;
import com.healthtop.utils.ResultResponese;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Optional;


@Log4j2
@RestController
@RequestMapping("/comment")
public class XsCommentController {

    @Autowired
    private XsCommentService commentService;

    @PostMapping("/addComment")
    public ResultResponese addComment(XsComment comment){
        try {
            Optional<XsComment> commentA = Optional.ofNullable(comment);
            if (!commentA.isPresent()) {
                return new ResultResponese().fail().message("参数不能为空");
            }
            comment = commentA.get();
            commentService.addComment(comment);
            return new ResultResponese().success().message("添加成功");
        }catch (Exception e){
            log.error("addComment发生异常,请求参数为:{},异常信息为:{}",comment,e);
            return new ResultResponese().fail();
        }
    }

    @GetMapping("searchComment")
    public ResultResponese searchComment(){

        return new ResultResponese().success().message("添加成功");
    }


}
